package model;

import java.io.*;

import model.*;



public class FileSaver {

	public FileSaver() {
	}

	public void saveFile(Board board) throws FileNotFoundException {


		String text = "Rajesh Kumar";
		File file = new File("gizmoballTest.txt");
		FileOutputStream fos = new FileOutputStream(file, false);
		PrintWriter pw = new PrintWriter(fos);

		

		int squareCount = 1;
		int circleCount = 1;
		int triangleCount = 1;
		int leftFlipperCount = 1;
		int rightFlipperCount = 1;
		
		

		for (int i = 0; i <= 19; i++) {
			for (int j = 0; j <= 19; j++) {
				if (board.getGizmo(i, j) != null) {

					if (board.getGizmo(i, j).getType() == "Square") {
						text = new String("Square S" + squareCount + " " + i
								+ " " + j);
						squareCount++;
					} else if (board.getGizmo(i, j).getType() == "Circle") {
						text = new String("Circle C" + circleCount + " " + i
								+ " " + j);
						circleCount++;
					} else if (board.getGizmo(i, j).getType() == "Triangle") {
						text = new String("Triangle T" + triangleCount + " "
								+ i + " " + j);
						
						
					} else if (board.getGizmo(i, j).getType() == "LeftFlipper") {
						text = new String("LeftFlipper LF" + leftFlipperCount + " " + i
								+ " " + j);
						leftFlipperCount++;
						
					} 
					else if (board.getGizmo(i, j).getType() == "RightFlipper") {
						text = new String("RightFlipper RF" + rightFlipperCount + " " + i
								+ " " + j);
						rightFlipperCount++;}
					else if (board.getGizmo(i, j).getType() == "Absorber") {
						text = new String("Absorber A 0 19 19 19");
					}

					{

						pw.println(text);
						if (board.getGizmo(i, j).getType() == "Triangle") {
							for (int k = 0; k < board.getGizmo(i, j).getTriangleRotations(); k++)
							{
								pw.println("Rotate T" + triangleCount);
							}
							triangleCount++;
						}

						System.out.println("Your file has been written");

					}
				}
			}
		}
		pw.close();
	}
}
